﻿Imports System.Data.SqlClient
Imports System.Configuration
Imports BEGestionProyecto
Public Class DLGPHoraRegistro
#Region "Consultar"

    'Funcion que carga la Lista de Categorias del Personal
    'fecha crea         fecha modifica         autor
    '01/02/2012         01/02/2012              JKP
    Public Function fuDProcesoVerificarAlGuardar(ByVal psHorcodPersona As Integer, ByVal pfHorfecConsumida As DateTime, _
            ByVal piPaccodProyectoActividad As Integer, ByVal piRegistrohoraID As Integer) As DataSet
        Try

            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            Dim lCmd As New SqlCommand("paGPHoraRegistroVerificarGuardarPRC", lCnx)
            lCmd.CommandType = CommandType.StoredProcedure
            lCmd.Parameters.Add("@pepPersonalID", SqlDbType.Int).Value = psHorcodPersona
            lCmd.Parameters.Add("@horFechRegistro", SqlDbType.DateTime).Value = pfHorfecConsumida
            lCmd.Parameters.Add("@horRegistrohoraID", SqlDbType.Int).Value = piRegistrohoraID

            Dim lDa As New SqlDataAdapter
            lDa.SelectCommand = lCmd
            'Llenar Dataset
            Dim lDs As New DataSet
            lDa.Fill(lDs)
            'Retornar Datos
            Return lDs
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return Nothing
        End Try
    End Function
    'Funcion que carga la Lista de Categorias del Personal
    'fecha crea         fecha modifica         autor
    '01/02/2012         01/02/2012              JKP
    Public Function fuDLListarHoraRegistroxFechas(ByVal piPersonalID As Integer, ByVal pfFechRegistroI As Date, ByVal pfFechRegistroF As Date) As DataTable
        Try

            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            Dim lCmd As New SqlCommand("paGPHoraRegistroxFechasLST", lCnx)
            lCmd.CommandType = CommandType.StoredProcedure
            lCmd.Parameters.Add("@pepPersonalID", SqlDbType.Int).Value = piPersonalID
            lCmd.Parameters.Add("@horFechRegistroI", SqlDbType.DateTime).Value = pfFechRegistroI
            lCmd.Parameters.Add("@horFechRegistroF", SqlDbType.DateTime).Value = pfFechRegistroF

            Dim lDa As New SqlDataAdapter
            lDa.SelectCommand = lCmd
            'Llenar Dataset
            Dim lDs As New DataSet
            lDa.Fill(lDs)
            'Retornar Datos
            Return lDs.Tables(0)
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return Nothing
        End Try
    End Function

    'Funcion que carga la Lista de Categorias del Personal
    'fecha crea         fecha modifica         autor
    '01/02/2012         01/02/2012              JKP
    Public Function fuDLBuscarHoraRegistrox(ByVal piRegistrohoraID As Integer) As DataTable
        Try

            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            Dim lCmd As New SqlCommand("paGPHoraRegistroBUSx", lCnx)
            lCmd.CommandType = CommandType.StoredProcedure
            lCmd.Parameters.Add("@horRegistrohoraID", SqlDbType.Int).Value = piRegistrohoraID

            Dim lDa As New SqlDataAdapter
            lDa.SelectCommand = lCmd
            'Llenar Dataset
            Dim lDs As New DataSet
            lDa.Fill(lDs)
            'Retornar Datos
            Return lDs.Tables(0)
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return Nothing
        End Try
    End Function


    Public Function fuDLListarProyectoxPersona(ByVal piPersonalID As Integer) As DataTable
        Try

            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            Dim lCmd As New SqlCommand("paGPProyectoxPersonaLST", lCnx)
            lCmd.CommandType = CommandType.StoredProcedure
            lCmd.Parameters.Add("@PersonalID", SqlDbType.Int).Value = piPersonalID

            Dim lDa As New SqlDataAdapter
            lDa.SelectCommand = lCmd
            'Llenar Dataset
            Dim lDs As New DataSet
            lDa.Fill(lDs)
            'Retornar Datos
            Return lDs.Tables(0)
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return Nothing
        End Try
    End Function
    Public Function fuDLListarActividadxPersona(ByVal piPersonalID As Integer, ByVal piProyectoID As Integer) As DataTable
        Try

            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            Dim lCmd As New SqlCommand("paGPProyectoActividadPersonaLST", lCnx)
            lCmd.CommandType = CommandType.StoredProcedure
            lCmd.Parameters.Add("@PersonalID", SqlDbType.Int).Value = piPersonalID
            lCmd.Parameters.Add("@ProyectoID", SqlDbType.Int).Value = piProyectoID

            Dim lDa As New SqlDataAdapter
            lDa.SelectCommand = lCmd
            'Llenar Dataset
            Dim lDs As New DataSet
            lDa.Fill(lDs)
            'Retornar Datos
            Return lDs.Tables(0)
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return Nothing
        End Try
    End Function




#End Region
#Region "Actualizar"
    'Funcion que carga la Lista de Categorias del Personal
    'fecha crea         fecha modifica         autor
    '01/02/2012         01/02/2012              JKP
    Public Function fuDLInsertarHoraRegistro(ByVal pBE As BEGPHoraRegistro) As Boolean
        Try
            'Se crea una variable sqlconnection
            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            'Se crea un sqlcommand
            Dim lCmd As New SqlCommand
            'Se crea la conexion para el command
            lCmd.Connection = lCnx
            'Se declara el typo de comando
            lCmd.CommandType = CommandType.StoredProcedure
            'Declaras el nombre del Store Procedure de Insertar Empleado
            lCmd.CommandText = "paGPHorasRegistroINS"
            'Definicion de Parametros para el procedure
            With lCmd.Parameters
                .Add(New SqlParameter("@horProyActPerID", SqlDbType.Int)).Value = pBE.HorProyActPerID
                .Add(New SqlParameter("@horFechRegistro", SqlDbType.SmallDateTime)).Value = pBE.HorFechRegistro
                .Add(New SqlParameter("@horHoraInicio", SqlDbType.DateTime)).Value = pBE.HorHoraInicio
                .Add(New SqlParameter("@horHoraFinal", SqlDbType.DateTime)).Value = pBE.HorHoraFinal
                .Add(New SqlParameter("@horCantMins", SqlDbType.Int)).Value = pBE.HorCantMins
                .Add(New SqlParameter("@horobsReghora", SqlDbType.VarChar)).Value = pBE.HorobsReghora
                .Add(New SqlParameter("@horEstado", SqlDbType.Bit)).Value = pBE.HorEstado
                .Add(New SqlParameter("@horUserCreacionID", SqlDbType.Int)).Value = pBE.HorUserCreacionID
            End With
            'Se cargan los parametros que viene de las entidades guardadas temporalmente
            lCnx.Open()
            lCmd.ExecuteNonQuery()
            lCnx.Close()
            Return True
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return False
        End Try
    End Function
    'Funcion que carga la Lista de Categorias del Personal
    'fecha crea         fecha modifica         autor
    '01/02/2012         01/02/2012              JKP
    Public Function fuDLActualizarHoraRegistro(ByVal pBE As BEGPHoraRegistro) As Boolean
        Try
            'Se crea una variable sqlconnection
            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            'Se crea un sqlcommand
            Dim lCmd As New SqlCommand
            'Se crea la conexion para el command
            lCmd.Connection = lCnx
            'Se declara el typo de comando
            lCmd.CommandType = CommandType.StoredProcedure
            'Declaras el nombre del Store Procedure de Insertar Empleado
            lCmd.CommandText = "paGPHorasRegistroUPD"
            'Definicion de Parametros para el procedure
            With lCmd.Parameters
                .Add(New SqlParameter("@horRegistrohoraID", SqlDbType.Int)).Value = pBE.HorRegistrohoraID
                .Add(New SqlParameter("@horProyActPerID", SqlDbType.Int)).Value = pBE.HorProyActPerID
                .Add(New SqlParameter("@horFechRegistro", SqlDbType.SmallDateTime)).Value = pBE.HorFechRegistro
                .Add(New SqlParameter("@horHoraInicio", SqlDbType.DateTime)).Value = pBE.HorHoraInicio
                .Add(New SqlParameter("@horHoraFinal", SqlDbType.DateTime)).Value = pBE.HorHoraFinal
                .Add(New SqlParameter("@horCantMins", SqlDbType.Int)).Value = pBE.HorCantMins
                .Add(New SqlParameter("@horobsReghora", SqlDbType.VarChar)).Value = pBE.HorobsReghora
                .Add(New SqlParameter("@horEstado", SqlDbType.Bit)).Value = pBE.HorEstado
                .Add(New SqlParameter("@horUserModificacion", SqlDbType.Int)).Value = pBE.HorUserModificacion
            End With
            'Se cargan los parametros que viene de las entidades guardadas temporalmente
            lCnx.Open()
            lCmd.ExecuteNonQuery()
            lCnx.Close()
            Return True
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return False
        End Try
    End Function


    'Funcion que carga la Lista de Categorias del Personal
    'fecha crea         fecha modifica         autor
    '01/02/2012         01/02/2012              JKP
    Public Function fuDLEliminarHoraRegistro(ByVal piRegistrohoraID As Integer, ByVal piUserModificacion As Integer) As Boolean
        Try
            'Se crea una variable sqlconnection
            Dim lCnx As New SqlConnection(ConfigurationManager.ConnectionStrings("GPConnectionString").ConnectionString)
            'Se crea un sqlcommand
            Dim lCmd As New SqlCommand
            'Se crea la conexion para el command
            lCmd.Connection = lCnx
            'Se declara el typo de comando
            lCmd.CommandType = CommandType.StoredProcedure
            'Declaras el nombre del Store Procedure de Insertar Empleado
            lCmd.CommandText = "paGPHorasRegistroDEL"
            'Definicion de Parametros para el procedure
            With lCmd.Parameters
                .Add(New SqlParameter("@horRegistrohoraID", SqlDbType.Int)).Value = piRegistrohoraID
                .Add(New SqlParameter("@horUserModificacion", SqlDbType.Int)).Value = piUserModificacion
            End With
            'Se cargan los parametros que viene de las entidades guardadas temporalmente

            lCnx.Open()
            lCmd.ExecuteNonQuery()
            lCnx.Close()
            Return True
        Catch ex As Exception
            Throw New ArgumentException("Descripcion : " & ex.Message)
            Return False
        End Try
    End Function
#End Region


End Class

